package org.sdnstproject.interlayer.OF13Protocal;

import org.projectfloodlight.openflow.types.U32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class FuAsyncGetReply {
	private static final Logger log = LoggerFactory.getLogger(FuAsyncGetReply.class);
    public byte version = (byte)4;
    public byte type = (byte)27;
    public short length = (short)32;// fixed value property length = 32
    public long xid = 0x0L;
    public long packetInMaskEqualMaster = 0x0L;
    public long packetInMaskSlave = 0x0L;
    public long portStatusMaskEqualMaster = 0x0L;
    public long portStatusMaskSlave = 0x0L;
    public long flowRemovedMaskEqualMaster = 0x0L;
    public long flowRemovedMaskSlave = 0x0L;
	
	public FuAsyncGetReply() {
		
	}
	
	public FuAsyncGetReply setField(String field, String value) {
		switch (field) {
		case "version":
			this.version = Byte.parseByte(value);
			break;
		case "type":
			this.type = Byte.parseByte(value);
			break;
		case "length":
			this.length = Short.parseShort(value);
			break;
		case "xid":
			this.xid = Long.parseLong(value);
			break;
		case "packetInMaskEqualMaster":
			this.packetInMaskEqualMaster = Long.parseLong(value);
			break;
		case "packetInMaskSlave":
			this.packetInMaskSlave = Long.parseLong(value);
			break;
		case "portStatusMaskEqualMaster":
			this.portStatusMaskEqualMaster = Long.parseLong(value);
			break;
		case "portStatusMaskSlave":
			this.portStatusMaskSlave = Long.parseLong(value);
			break;
		case "flowRemovedMaskEqualMaster":
			this.flowRemovedMaskEqualMaster = Long.parseLong(value);
			break;
		case "flowRemovedMaskSlave":
			this.flowRemovedMaskSlave = Long.parseLong(value);
			break;
		}
		return this;
	}
	
	public ByteBuf writeTo() {
		ByteBuf bb = Unpooled.directBuffer();
		 // fixed value property version = 4
        bb.writeByte(version);
        // fixed value property type = 27
        bb.writeByte(type);
        // fixed value property length = 32
        bb.writeShort(length);
        bb.writeInt(U32.t(xid));
        bb.writeInt(U32.t(packetInMaskEqualMaster));
        bb.writeInt(U32.t(packetInMaskSlave));
        bb.writeInt(U32.t(portStatusMaskEqualMaster));
        bb.writeInt(U32.t(portStatusMaskSlave));
        bb.writeInt(U32.t(flowRemovedMaskEqualMaster));
        bb.writeInt(U32.t(flowRemovedMaskSlave));
        return bb;
    }
	
	@Override
    public String toString() {
        StringBuilder b = new StringBuilder("OFAsyncGetReplyVer13(");
        b.append("version=").append(version);
        b.append(", ");
        b.append("type=").append(type);
        b.append(", ");
        b.append("length=").append(length);
        b.append(", ");
        b.append("xid=").append(xid);
        b.append(")");
        b.append("packetInMaskEqualMaster=").append(packetInMaskEqualMaster);
        b.append(", ");
        b.append("packetInMaskSlave=").append(packetInMaskSlave);
        b.append(", ");
        b.append("portStatusMaskEqualMaster=").append(portStatusMaskEqualMaster);
        b.append(", ");
        b.append("portStatusMaskSlave=").append(portStatusMaskSlave);
        b.append(", ");
        b.append("flowRemovedMaskEqualMaster=").append(flowRemovedMaskEqualMaster);
        b.append(", ");
        b.append("flowRemovedMaskSlave=").append(flowRemovedMaskSlave);
        b.append(")");
        return b.toString();
    }
}
